#include "Camera.h"

CCamera::CCamera()
{

}

CCamera::CCamera(float posX, float posY)
{
	m_posX = posX;
	m_posY = posY;
	m_width = CAMERA_WIDTH;
	m_heigth = CAMERA_HEIGHT;

	D3DXMatrixIdentity(&MatrixTransform);
	MatrixTransform._22 = -1;
}

CCamera::CCamera(float posX, float posY, float width, float heigth)
{
	m_posX = posX;
	m_posY = posY;
	m_width = width;
	m_heigth = heigth;	

	D3DXMatrixIdentity(&MatrixTransform);
	MatrixTransform._22 = -1;

}

D3DXMATRIX CCamera::getViewPort()
{
	D3DXMatrixIdentity(&m_viewPort);
	D3DXMatrixAffineTransformation(&m_viewPort, 1, &D3DXVECTOR3(0, 0, 0), &D3DXQUATERNION(0, 0, 0, 0), &D3DXVECTOR3(m_posX,m_posY, 0));
	m_viewPort._22 = -1;
	return m_viewPort;
}


D3DXVECTOR2 CCamera::getPointTransform(float x, float y)
{
	
	MatrixTransform._41 = -m_posX;
	MatrixTransform._42 = m_posY;

	D3DXVECTOR3 pos(x, y, 0);
	D3DXVECTOR4 result;
	D3DXVec3Transform(&result, &pos, &MatrixTransform);
	return D3DXVECTOR2(result.x, result.y);
}

void CCamera::update(float time, D3DXVECTOR2 pos)
{	
	float posX = pos.x;
	float posY = pos.y;

	if (posX >= CAMERA_WIDTH/2 + m_posX )
	{
		m_posX = posX - CAMERA_WIDTH / 2;
	}
}

void CCamera::setPostion(float posX, float posY)
{
	m_posX = posX;
	m_posY = posY;
}

CCamera::~CCamera()
{

}